<?php

namespace App\Kits\Validator\Rules;


use Illuminate\Validation\Validator;

/**
 * 某字段等于某值时 验证小于
 * Class LtWithRule
 * @package App\Kits\Validator\Rules
 */
class LtIfRule implements RuleInterface
{
    const NAME = 'lt_if';


    /**
     * @param $attribute
     * @param $value
     * @param $parameters
     * @param Validator $validator
     * @return bool
     */
    public function passes($attribute, $value, $parameters, Validator $validator): bool
    {
        $data = $validator->getData();
        if ($data[$parameters[1]] != $parameters[2]) {
            return true;
        }
        return bccomp($parameters[0], $value, 2) > 0;
    }

    /**
     *
     * @param $message
     * @param $attribute
     * @param $rule
     * @param $parameters
     * @param Validator $validator
     * @return string
     */
    public function message($message, $attribute, $rule, $parameters, Validator $validator): string
    {
        return str_replace(':value', $parameters[0], $message);
    }
}
